#include <iostream>
#include "Shm.hpp"
#include "NamePipe.hpp"
#include <string>

void ModifyMessageForSend(char *ShmAddress)
{
    std::string message;
    std::getline(std::cin, message);
    for (int i = 0; i < message.size(); i++)
        ShmAddress[i] = message[i];
}
void Worklient(Shm &shm)
{
    char *shmaddr = (char *)shm.GetShmAddr();
    // 使用管道保证通信安全
    NamePiped fifo(pathname, User);
    sleep(2);
    fifo.OpenForWrite();
    // 客户端开始写入
    while (true)
    {
        shm.CleanShm();
        ModifyMessageForSend(shmaddr);
        std::string MessageTip("once write done");
        std::cout << MessageTip << std::endl;
        fifo.WritePipeData(MessageTip);
        sleep(2);
    }
}
int main()
{
    Shm shm(static_path, Proj_id, User);
    Worklient(shm);
    return 0;
}